#coding=utf-8
import glob
import jieba
import re
import json
from common.attr_v2 import AttrV2
from database.db_handler import MysqlHander

'''
v2属性入库
600021|0|2001|上证指数|0|
实体代码|实体类型|关系类型id|关系属性名称|排序编号|
'''

class AttrV2Data:
    def __init__(self, file):
        self.db = MysqlHander("config.ini")
        self.table = ""
        self.file = file
        self.v2 = AttrV2()

    def write_db(self, d):
        data = d.split("|")
        if len(data) == 0:
            return
        self.v2.add_relation(self.db, data[0], data[1], data[2], data[3], data[4])
    
    def record_attr(self):
        with open(self.file, 'r', encoding='utf-8') as f:
            self.data = f.readlines()
        for b in self.data:
            self.write_db(b)

if __name__ == '__main__':
    code = AttrV2Data('./out/shangjiaosuo_zhishu_relation.txt')
    code.record_attr()
    code1 = AttrV2Data('./out/shenjiaosuo_zhishu_relation_v1.txt')
    code1.record_attr()